package com.xuecheng.search.controller;

import com.xuecheng.commons.model.dto.CoursePubIndexDto;
import com.xuecheng.commons.model.dto.PageRequest;
import com.xuecheng.commons.model.vo.ResponseResult;
import com.xuecheng.search.domain.CoursePubIndex;
import com.xuecheng.search.service.SearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;

@RestController
public class SearchController {
    @Autowired
    private SearchService searchService;

    /**
     * 根据条件查询课程
     * @param pageRequest
     * @param coursePubIndexDto
     * @return
     */
    @PostMapping("/course-search")
    public ResponseResult searchCourse(PageRequest pageRequest, @RequestBody CoursePubIndexDto coursePubIndexDto){
        return searchService.searchCourse(pageRequest,coursePubIndexDto);
    }

    /**
     * 根据id查询课程
     * @param id
     * @return
     * @throws IOException
     */
    @GetMapping("/course-search/{id}")
    public ResponseResult findById(@PathVariable("id")String id) throws IOException {
        return searchService.findById(id);
    }
}
